package com.example.demo.controller;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JWindow;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.druid.pool.vendor.SybaseExceptionSorter;
import com.example.demo.bean.DfyzWebsiteRole;
import com.example.demo.bean.Entity;
import com.example.demo.dao.DfyzWebsiteRoleMapper;
import com.example.demo.utils.JwtHelper;

import net.sf.ehcache.Cache;

@CrossOrigin(allowCredentials = "true", origins = "*", maxAge = 3600, methods = { RequestMethod.GET, RequestMethod.POST,
		RequestMethod.PUT,
		RequestMethod.OPTIONS }, allowedHeaders = { "x-requested-with", "accept", "authorization", "content-type" })
@RestController
public class Controller2 {
	protected final Logger logger = LogManager.getLogger(this.getClass());

	@Autowired
	RedisTemplate redis;
	
	@Autowired
	private Entity entity;
	

	@Autowired
	DfyzWebsiteRoleMapper dfyzWebsiteRole;

	@RequestMapping("/test")
	public Object test (HttpServletRequest request, HttpServletResponse response) {
		String token = JwtHelper.token();
		redis.opsForValue().set("TOKEN:"+token, entity);
		response.setHeader("token", token);
		Object object = redis.opsForValue().get("TOKEN:"+token);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("token", "TOKEN:"+token);
		map.put("entity", object);
		return map;
	}
	@RequestMapping("/test2")
	public Object tes2t (HttpServletRequest request, HttpServletResponse response) {
		String header = request.getHeader("token");
		Map map = new HashMap<String,String>();
		map.put("aa", "aa");
		map.put("bb", "aa");
		map.put("cc", "aa");
		map.put("dd", "aa");
		map.put("ee", "aa");
		map.values().forEach(System.out::println);
		return map;
		
		
	}
}
